package com.crayon.cardbiz.fragment;



import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.ListFragment;
import android.util.Log;
import android.view.View;
import android.widget.ListView;

import com.crayon.cardbiz.adaper.AdapterBaseEntry;
import com.crayon.cardbiz.dic.EntryDic;

abstract public class FragmentListMenuRoot extends ListFragment {
	
	public interface OnEntryMenuSelectListener{
		public void onSelectedEntry(EntryDic entry);
	}
	abstract public EntryDic[] getEntrys();
	AdapterBaseEntry mAdapter;
	OnEntryMenuSelectListener onEntryMenuSelectListener;
	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		super.onActivityCreated(savedInstanceState);
		mAdapter = new AdapterBaseEntry(getActivity(),android.R.layout.simple_list_item_1, getEntrys());
		setListAdapter(mAdapter);
	}

	@Override
	public void onListItemClick(ListView l, View v, int position, long id) {
		Log.i("FragmentList", "Item clicked: " + id);
		if(getOnEntryMenuSelectListener()!=null){
			EntryDic item = mAdapter.getItem(position);
			getOnEntryMenuSelectListener().onSelectedEntry(item);
		}
	}
	
	@Override
	public void onAttach(Activity activity) {
		// TODO Auto-generated method stub
		super.onAttach(activity);
		if(activity instanceof OnEntryMenuSelectListener){
			setOnEntryMenuSelectListener((OnEntryMenuSelectListener)activity);
		}
	}

	public OnEntryMenuSelectListener getOnEntryMenuSelectListener() {
		return onEntryMenuSelectListener;
	}

	public void setOnEntryMenuSelectListener(
			OnEntryMenuSelectListener onEntryMenuSelectListener) {
		this.onEntryMenuSelectListener = onEntryMenuSelectListener;
	}

}
